import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { CommentService } from './comment.service';
import { CreateCommentDto } from './dto/create-comment.dto';
import { UpdateCommentDto } from './dto/update-comment.dto';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiParam,
  ApiQuery,
  ApiBody,
  ApiCreatedResponse,
  ApiOkResponse,
  ApiNotFoundResponse,
} from '@nestjs/swagger';
import { Public } from '../common/isPublic';
@ApiTags('文章评论')
@Controller('comment')
@Public()
export class CommentController {
  constructor(private readonly commentService: CommentService) {}

  @Post()
  @ApiOperation({ summary: '创建一个新的评论' })
  @ApiBody({ type: CreateCommentDto })
  @ApiCreatedResponse({ description: '评论创建成功', type: CreateCommentDto })
  create(@Body() createCommentDto: CreateCommentDto) {
    return this.commentService.create(createCommentDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有评论' })
  @ApiOkResponse({ description: '评论列表获取成功', type: [CreateCommentDto] })
  findAll() {
    return this.commentService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取单个评论' })
  @ApiParam({ name: 'id', description: '评论ID' })
  @ApiOkResponse({ description: '评论信息获取成功', type: CreateCommentDto })
  @ApiNotFoundResponse({ description: '评论不存在' })
  findOne(@Param('id') id: string) {
    return this.commentService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新一个评论' })
  @ApiParam({ name: 'id', description: '评论ID' })
  @ApiBody({ type: UpdateCommentDto })
  @ApiOkResponse({ description: '评论更新成功', type: UpdateCommentDto })
  update(@Param('id') id: string, @Body() updateCommentDto: UpdateCommentDto) {
    return this.commentService.update(+id, updateCommentDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除一个评论' })
  @ApiParam({ name: 'id', description: '评论ID' })
  @ApiOkResponse({ description: '评论删除成功' })
  @ApiNotFoundResponse({ description: '评论不存在' })
  remove(@Param('id') id: string) {
    return this.commentService.remove(+id);
  }
}
